//
//  BaseGameNode.m
//  flybike
//
//  Created by Eric on 12-12-20.
//
//

#import "BaseGameNode.h"


@implementation BaseGameNode
@synthesize world=world_;

@synthesize screenW = screenW_;
@synthesize screenH = screenH_;

+ (CCScene*) scene {
	CCScene *scene = [CCScene node];
	[scene addChild:[self node]];
	return scene;
}

-(id)init{
    if( (self=[super init])) {
        [self initParameter];
        [self createBox2DWorld];
        [self initPhysics];
    }
    return self;
}
-(void) initParameter{
    
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    screenW_ = screenSize.width;
    screenH_ = screenSize.height;
    
    

}
- (void) createBox2DWorld {
	
	b2Vec2 gravity;
	gravity.Set(0.0f, -9.8f);
//    gravity.Set(0.0f, -1.10f);
	
	world_ = new b2World(gravity, false);
    
#ifdef DRAW_BOX2D_WORLD
	
	render_ = new GLESDebugDraw([Box2DHelper pointsPerMeter]);
	world_->SetDebugDraw(render_);
	
	uint32 flags = 0;
	flags += b2Draw::e_shapeBit;
	flags += b2Draw::e_jointBit;
	flags += b2Draw::e_aabbBit;
	flags += b2Draw::e_pairBit;
	flags += b2Draw::e_centerOfMassBit;
	render_->SetFlags(flags);
	
#endif
}

-(void) initPhysics{
    m_contactListener = new MyContactListener();
	world_->SetContactListener( m_contactListener );
	
	// contact filter
//    m_contactFilter = new MyContactFilter();
//    world_->SetContactFilter( m_contactFilter );
	
	// destruction listener
	m_destructionListener = new MyDestructionListener();
	world_->SetDestructionListener( m_destructionListener );
}

-(void)dealloc{
#ifdef DRAW_BOX2D_WORLD
	delete render_;
	render_ = NULL;
	
#endif
	delete world_;
	world_ = NULL;
    [super dealloc];
}
@end
